package edu.princeton.cs.algs4;

import edu.princeton.cs.stdlib.StdOut;

/*************************************************************************
 *  Compilation:  javac DirectedEdge.java
 *  Execution:    java DirectedEdge
 *
 *  Immutable weighted directed edge.
 *
 *************************************************************************/

/**
 * The <tt>DirectedEdge</tt> class represents a weighted edge in an directed
 * graph.
 * <p>
 * For additional documentation, see <a href="/algs4/44sp">Section 4.4</a> of
 * <i>Algorithms, 4th Edition</i> by Robert Sedgewick and Kevin Wayne.
 */

public class DirectedEdge {
	private final int v;
	private final int w;
	private final double weight;
	
	/**
	 * Create a directed edge from v to w with given weight.
	 */
	public DirectedEdge(int v, int w, double weight) {
		this.v = v;
		this.w = w;
		this.weight = weight;
	}

	/**
	 * Return the vertex where this edge begins.
	 */
	public int from() {
		return v;
	}

	/**
	 * Return the vertex where this edge ends.
	 */
	public int to() {
		return w;
	}

	/**
	 * Return the weight of this edge.
	 */
	public double weight() {
		return weight;
	}

	/**
	 * Return a string representation of this edge.
	 */
	public String toString() {
		return v + "->" + w + " " + String.format("%5.2f", weight);
	}

	/**
	 * Test client.
	 */
	public static void main(String[] args) {
		DirectedEdge e = new DirectedEdge(12, 23, 3.14);
		StdOut.println(e);
	}
}
